const http = require('http');
const fs = require('fs');

http.createServer(function (request, response) {

  // 1、获取地址
  let pathName = request.url
  // 2、通过fs模块读取文件
  if (pathName === '/') {
    fs.readFile('./static/views/index.html', (err, data) => {
      if (err) {
        setResponse(response, 404,'喔唷，你访问的页面丢失了...')
      }
      setResponse(response, 200, data)
    })
  }

  

}).listen(8081);

function setResponse(res, status, data) {
  res.writeHead(status, {'Content-Type': 'text/html;charset="utf-8"'});
  res.end(data);
}